#include <vector>

using namespace std;

// 利用前缀和快速得到区域累加和
// 测试链接 : https://leetcode.cn/problems/range-sum-query-immutable/

class NumArray 
{
private:
    vector<int> sum;

public:
    NumArray(vector<int>& nums) 
    {
        sum.resize(nums.size() + 1);
        for(int i = 1; i <= nums.size(); ++i)
        {
            sum[i] = sum[i - 1] + nums[i - 1];
        }
    }
    
    int sumRange(int left, int right) 
    {
        return sum[right + 1] - sum[left];
    }
};